/**
 * Copyright (c) 2007,中企动力华南研发中心<br>
 * All rights reserved.<br>
 */
package com.ce.pms.charge.web;

import com.ce.pms.base.web.PmsBaseAction;
import com.ce.pms.charge.model.BankDomain;
import com.ce.pms.charge.service.IFeeBankService;
import com.ce.pms.charge.vo.BankVO;
import com.ce.pms.exception.UILayerException;
import com.sitechasia.webx.components.xtable.util.ExtremeUtils;
import com.sitechasia.webx.core.annotation.Out;
import com.sitechasia.webx.core.annotation.Read;
import com.sitechasia.webx.core.support.Page;

/**
 * 功能描述：<br>
 * @author 易贤建 创建日期：2008-8-1<br>
 */
public class FeeBankAction extends PmsBaseAction {

	private IFeeBankService feeBankService = null;

	/**
	 * 功能描述:  初始化划款银行主页面<br>
	 * Create author:yixianjian <br>
	 * Create on:2008-8-1  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public String initFeeBankMain(){
		return "feeBankMain";
	}

	/**
	 * 功能描述:  初始化划款银行列表页面, 默认按银行名称升序排序<br>
	 * @param flag
	 * @param currentPage
	 * @param pageSize
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-8-4  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public String initFeeBankList(@Read (key="contextMenuFlag") String flag,
			 				   @Read(key = "ec_p",defaultValue="1") Integer currentPage,
			 				   @Read(key = "ec_crd",defaultValue="15")Integer pageSize){
		String order = ExtremeUtils.getSortOrder(getRequest());
		Page page = feeBankService.queryAllFeeBankByPage(currentPage, pageSize,order);
		setAttribute("bank", page.getResult());
		setAttribute("totalRows", Integer.valueOf(String.valueOf(page.getTotalCount())));
		return "feeBankList";
	}

	/**
	 * 功能描述: 初始化划款银行添加页面 <br>
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-8-4  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public String initFeeBankAdd(@Read(key="optFlag") @Out(key="optFlag")String optFlag ){
		setAttribute("method","addFeeBank");
		return "feeBankOpt";
	}
	/**
	 * 功能描述:  初始化划款银行修改页面<br>
	 * @param bankId
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-9-5  <br>
	 */
	public String initFeeBankEdit(@Read(key="bankId")Long bankId){
		BankVO bankVO = feeBankService.getFeeBankById(bankId);
		setAttribute("bankVO", bankVO);
		setAttribute("method", "editFeeBank");
		return"feeBankOpt";
	}
	/**
	 * 功能描述: 检查银行是否被引用了。如果被引用了，就不能修改 <br>
	 * true  说明被引用了  false说明没被引用了
	 * @param bankId
	 * Create author:yixianjian <br>
	 * Create on:2008-9-5  <br>
	 */
	public void checkBankIsUsed(@Read(key="bankId")Long bankId){
		boolean flag = feeBankService.checkBankIsUsed(bankId);
		renderText(String.valueOf(!flag));
	}
	/**
	 * 功能描述:  添加划款银行<br>
	 * @param bankVO
	 * Create author:yixianjian <br>
	 * Create on:2008-8-5  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public void addFeeBank(@Read BankVO bankVO){
		bankVO.setCreator(getUserId());
		feeBankService.addFeeBank(bankVO);
	}

	/**
	 * 功能描述:  修改划款银行设置<br>
	 * @param bankVO
	 * Create author:yixianjian <br>
	 * Create on:2008-8-5  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public void editFeeBank(@Read BankVO bankVO){
		bankVO.setModifier(getUserId());
		feeBankService.editFeeBank(bankVO);
	}

	/**
	 * 功能描述: 根据ID 删除划款银行设置 <br>
	 * @param bankID
	 * Create author:yixianjian <br>
	 * Create on:2008-8-5  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public void deleteFeeBank(@Read(key="bankID") Long bankID){
		try{
		feeBankService.deleteFeeBankById(bankID);
		}catch(Exception ex){
			throw new UILayerException("common:delete_error_exception");
		}
	}

	/**
	 * 功能描述:  验证银行名称唯一<br>
	 * @param bankName
	 * Create author:yixianjian <br>
	 * Create on:2008-8-5  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public void validateFeeBankName(@Read(key="bankName") String bankName,
									@Read(key="keyword") Long keyword){
		Boolean flag = feeBankService.checkBankNameIsOnly(bankName, keyword);
		renderText(String.valueOf(!flag));
	}
	/**
	 * 功能描述: 检查银行代码是否唯一<br>
	 * @param bankCode
	 * @param bankId
	 * Create author:yixianjian <br>
	 * Create on:2008-8-5  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public void validateFeeBankCode(@Read(key="bankCode") String bankCode,
									@Read(key="keyword") Long bankId){
		Boolean flag = feeBankService.checkBankCodeIsOnly(bankCode, bankId);
		renderText(String.valueOf(!flag));
	}
	/**
	 * 功能描述:  验证划款银行输出前缀是否唯一<br>
	 * @param oFilePrefix
	 * @param bankId
	 * Create author:yixianjian <br>
	 * Create on:2008-8-5  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public void validateFeeBankFilePrefix(@Read(key="outFilePrefix") String outFilePrefix,
										  @Read(key="keyword") Long bankId){
		Boolean flag = feeBankService.checkoFilePrefixIsOnly(BankDomain.OUT + outFilePrefix, bankId);
		renderText(String.valueOf(!flag));
	}
	public IFeeBankService getFeeBankService() {
		return feeBankService;
	}

	public void setFeeBankService(IFeeBankService feeBankService) {
		this.feeBankService = feeBankService;
	}
}
